<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-row>
		  <p-col  :span="24">
			<p-form-item label="组织" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'organization', validatorRules.organization]" placeholder="请输入组织"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="员工编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'empno', validatorRules.empno]" placeholder="请输入员工编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="员工姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'empname', validatorRules.empname]" placeholder="请输入员工姓名"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['empsex', validatorRules.empsex]" :trigger-change="true" dictCode="sex" placeholder="请选择性别"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="出生年月" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择出生年月" v-decorator="[ 'borndt', validatorRules.borndt]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="在职状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['holdflg', validatorRules.holdflg]" :trigger-change="true" dictCode="mes_holdflg" placeholder="请选择在职状态"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="入职日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择入职日期" v-decorator="[ 'registerdt', validatorRules.registerdt]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="离职日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择离职日期" v-decorator="[ 'dimissidt', validatorRules.dimissidt]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="雇佣性质" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['employNature', validatorRules.employNature]" :trigger-change="true" dictCode="mes_employ_nature" placeholder="请选择雇佣性质"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'status', validatorRules.status]" placeholder="请输入状态"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'telephone', validatorRules.telephone]" placeholder="请输入电话"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['edulevel', validatorRules.edulevel]" :trigger-change="true" dictCode="mes_edulevel" placeholder="请选择学历"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomname', validatorRules.workroomname]" placeholder="请输入车间"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomno', validatorRules.workroomno]" placeholder="请输入车间编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mobilePhone', validatorRules.mobilePhone]" placeholder="请输入手机"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="劳务公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'serviceCompany', validatorRules.serviceCompany]" placeholder="请输入劳务公司"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						dest-fields="lineid,lineno,linename,workroomid,workroomno,workroomname"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="直接/间接" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['diPower', validatorRules.diPower]" :trigger-change="true" dictCode="mes_di_power" placeholder="请选择直接/间接"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'classname', validatorRules.classname]" placeholder="请输入班组"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="人力分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['manpowerClassify', validatorRules.manpowerClassify]" :trigger-change="true" dictCode="mes_manpower_classify" placeholder="请选择人力分类"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="职务" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['duty', validatorRules.duty]" :trigger-change="true" dictCode="mes_duty" placeholder="请选择职务"/>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesHrEmployeeinfoModal",
    mixins: [SubmitOnchangMixin],
    components: {
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          organization: {rules: [
          ]},
          empno: {rules: [
          ]},
          empname: {rules: [
          ]},
          empsex: {rules: [
          ]},
          borndt: {rules: [
          ]},
          holdflg: {rules: [
          ]},
          registerdt: {rules: [
          ]},
          dimissidt: {rules: [
          ]},
          employNature: {rules: [
          ]},
          status: {rules: [
          ]},
          telephone: {rules: [
          ]},
          edulevel: {rules: [
          ]},
          workroomname: {rules: [
          ]},
          workroomno: {rules: [
          ]},
          mobilePhone: {rules: [
          ]},
          serviceCompany: {rules: [
          ]},
          linename: {rules: [
          ]},
          lineno: {rules: [
          ]},
          diPower: {rules: [
          ]},
          classname: {rules: [
          ]},
          manpowerClassify: {rules: [
          ]},
          duty: {rules: [
          ]},
        },
        url: {
          add: '/mes-manpower/auto/mesHrEmployeeinfo/add',
          edit: '/mes-manpower/auto/mesHrEmployeeinfo/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'organization','empno','empname','empsex','borndt','holdflg','registerdt','dimissidt','employNature','status','telephone','edulevel','workroomname','workroomno','mobilePhone','serviceCompany','linename','lineno','diPower','classname','manpowerClassify','duty'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              let formData = Object.assign(this.model, values);
              this.formData = Object.assign(this.model, values);
              //新增触发
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
                if(this.EnhanceJS.afterAdd){
                  //新增之前
                  let Obj = eval(this.EnhanceJS.afterAdd)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }else{
                //编辑触发
                httpurl+=this.url.edit;
                method = 'put';
                if(this.EnhanceJS.afterEdit){
                 //编辑之前
                  let Obj = eval(this.EnhanceJS.afterEdit)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'organization','empno','empname','empsex','borndt','holdflg','registerdt','dimissidt','employNature','status','telephone','edulevel','workroomname','workroomno','mobilePhone','serviceCompany','linename','lineno','diPower','classname','manpowerClassify','duty'))
      },


    }
  }
</script>